package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	r.GET("/welcome", welcome)
	r.POST("/welcome", formPost)

	r.Run()
}

func welcome(c *gin.Context) {
	// firstName是严格区分大小写的
	firstName := c.DefaultQuery("firstName", "bobby")
	// lastName := c.Query("first")
	lastName := c.DefaultQuery("lastName", "immoc")

	c.JSON(http.StatusOK, gin.H{
		"firstName": firstName,
		"lastName":  lastName,
	})
}

func formPost(c *gin.Context) {
	message := c.PostForm("message.proto")
	nick := c.DefaultPostForm("nick", "anonymous")
	c.JSON(http.StatusOK, gin.H{
		"message.proto": message,
		"nick":          nick,
	})
}
